package com.itheima.day2.exercise;

import java.util.ArrayList;
import java.util.List;
import java.util.function.Function;

public class Exercise2 {

    static List<String> map(List<Integer> list) {
        List<String> result = new ArrayList<>();
        for (Integer number : list) {
            // 转换：将数字转为字符串，但以后可能改变转换规则
            // (Integer number) -> String.valueOf(number)
            result.add(String.valueOf(number));
        }
        return result;
    }

    static List<String> map(List<Integer> list, Function<Integer, String> function) {
        List<String> result = new ArrayList<>();
        for (Integer number : list) {
            // 转换：将数字转为字符串，但以后可能改变转换规则
            result.add(function.apply(number));
        }
        return result;
    }

    public static void main(String[] args) {
        List<String> filter = map(List.of(1, 2, 3, 4, 5), (Integer number) -> String.valueOf(number));
        System.out.println(filter);
    }

}
